package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@Slf4j
@Api(tags = "菜品相关接口")
@RequestMapping("admin/dish")
@RestController
public class DishController {
    private final DishService dishService;

    public DishController(DishService dishService) {
        this.dishService = dishService;
    }

    /**
     * 新增菜品
     * @param dto 传入DTO
     * @return data 无
     */
    @ApiOperation("菜品添加")
    @PostMapping
    public Result<Object> addDish(@RequestBody DishDTO dto){
        log.info("菜品添加: {}", dto.toString());
        dishService.addDish(dto);
        return Result.success();
    }

    /**
     * 分页查询
     * @param queryDTO 请求参数 参数列表类型
     * @return PageResult
     */
    @ApiOperation("分页查询菜品列表")
    @GetMapping("/page")
    public Result<PageResult> pageDish(DishPageQueryDTO queryDTO){
        log.info("分页查询:{}", queryDTO.toString());
        PageResult result= dishService.pageDish(queryDTO);
        return Result.success(result);
    }

    /**
     * 删除菜品
     * @param ids 菜品id
     * @return null
     */
    @ApiOperation("删除菜品")
    @DeleteMapping
    public Result<Object> deleteDish(@RequestParam List<Long> ids){
        log.info("删除菜品ids: {}", ids.toString());
        dishService.deleteDish(ids);
        return Result.success();
    }

    /**
     * 根据id查询菜品数据
     * @param id 菜品id
     * @return dishVO
     */
    @ApiOperation("回显菜品")
    @GetMapping("/{id}")
    public Result<DishVO> getById(@PathVariable Long id){

        DishVO dishVO = dishService.getById(id);
        return Result.success(dishVO);
    }

    /**
     * 修改菜品
     * @param dto 菜品DTO
     * @return null
     */
    @ApiOperation("修改菜品")
    @PutMapping
    public Result<?> updateDish(@RequestBody DishDTO dto){
        log.info("修改菜品");
        dishService.update(dto);
        return Result.success();
    }

}
